package com.leetcode.weekly.contest.no281th;


/**
 * @author 覃国强
 * @date 2022-02-20 10:55
 */
public class A02_合并零之间的节点 {

  static
  class Solution {

    public ListNode mergeNodes(ListNode head) {

      ListNode result = new ListNode();
      ListNode curNode = result;
      while (head.next != null) {
        if (head.val != 0) {
          curNode.val += head.val;
        } else {
          curNode.next = new ListNode();
          curNode = curNode.next;
        }
        head = head.next;
      }

      return result.next;
    }

  }

  static
  class ListNode {

    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
      this.val = val;
    }

    ListNode(int val, ListNode next) {
      this.val = val;
      this.next = next;
    }
  }
}

